package com.hhz.time.part2;

import org.junit.Test;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 时间转换器
 *
 * @Author Rem
 * @Date 2020-02-15
 */

public class TestDateTimeFormatter {

    @Test
    public void test() {

        LocalDateTime now = LocalDateTime.now();
        System.out.println("当前时间" + now);

        DateTimeFormatter isoDate = DateTimeFormatter.ISO_DATE_TIME;
        System.out.println("String类型" + now.format(isoDate));

        //指定类型
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("YYYY年MM月dd日 hh:mm:ss");
        String strDate = dtf2.format(now);
        System.out.println("指定类型:" + strDate);

        //解析

        //jdk8报错  jdk9修复
        // LocalDateTime parse = LocalDateTime.parse("2012-02-02");
    }
}
